package com.china.zhuoyue.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.china.zhuoyue.R;
import com.china.zhuoyue.config.ConstantsKt;
import com.china.zhuoyue.ui.activity.commom.WebViewActivityKt;
import com.china.zhuoyue.ui.utils.SafeDialogHandle;
import com.china.zhuoyue.ui.utils.ViewSpanUtil;
import com.china.zhuoyue.ui.widget.BpClickableSpan;
import com.china.zhuoyue.ui.widget.ContactTextView;

/**
 * Created by zhoucl on 2019/12/10 0010.
 */
public class SecretDialog extends Dialog implements View.OnClickListener {
    ContactTextView tvSecret;
    private View.OnClickListener mOnClickListener;
    private Context mContext;

    public SecretDialog(@NonNull Context context) {
        super(context, R.style.dimLoadingdialog);
        mContext = context;
        init();
    }

    private void init() {
        setContentView(R.layout.dialog_secret);
        tvSecret = findViewById(R.id.tv_secret);
        ViewSpanUtil.Builder(tvSecret, getContext().getString(R.string.text_secret), getContext().getString(R.string.text_user_procotol))
                .setClickableSpan(new BpClickableSpan(null, v -> WebViewActivityKt.openUrl(mContext, ConstantsKt.USER_PROCOTOL)))
                .changeSpanText(getContext().getString(R.string.text_secret_procotol))
                .setClickableSpan(new BpClickableSpan(null, v -> WebViewActivityKt.openUrl(mContext, ConstantsKt.SECRET_PROCOTOL))).submit();
        Window window = getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = (int) (getContext().getResources().getDisplayMetrics().widthPixels * 0.8);
        attributes.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setAttributes(attributes);
        setCancelable(false);

        findViewById(R.id.btn_confirm).setOnClickListener(this);
        findViewById(R.id.btn_cancel).setOnClickListener(this);
    }

    public void onClick(View view) {
        SafeDialogHandle.safeDismissDialog(this);
        if (mOnClickListener != null)
            mOnClickListener.onClick(view);
    }

    public void setOnClickListener(View.OnClickListener mOnClickListener) {
        this.mOnClickListener = mOnClickListener;
    }
}
